<template>
  <!-- 提货单修改 -->
  <div class="billOrder_styl" v-if="modalShow">
    <Modal
      ref="modalEle"
      v-model="modalShow"
      width="600"
      class="modal-styl"
      :mask-closable="false"
    >
      <p slot="header" style="text-align: center">
        <span>立即购买</span>
      </p>
      <div class="title_styl">
        <div style="width: 50%">销售公司:{{ infoData.companyName }}</div>
        <div style="width: 50%">规格名称:{{ infoData.productAttrName }}</div>
      </div>
      <div class="infos_styl">
        <div class="smallInfo_styl">
          <div class="text_styl">{{ infoData.nnum }}吨</div>
          <div style="text-align: center">购买数量</div>
        </div>
        <div class="smallInfo_styl">
          <div class="textRed_styl">
            {{ infoData.nmoney || 0 }}元
            <Button
              shape="circle"
              icon="md-sync"
              class="reButton_styl"
              @click="getUserMoneyFun()"
            ></Button>
          </div>
          <div style="text-align: center">您的余额</div>
        </div>
        <div class="smallInfo_styl">
          <div class="text_styl">{{ infoData.nmoney }}元</div>
          <div style="text-align: center">订单总价</div>
        </div>
      </div>
      <div slot="footer">
        <Button type="text" @click="modalShow = false">取消</Button>
        <Button :loading="btnLoading" type="primary" @click="submitFun"
          >保存</Button
        >
      </div>
    </Modal>
    <Modal
      ref="modalEle"
      v-model="modalShowSuccess"
      width="600"
      class="modal-styl"
      :mask-closable="false"
    >
      <p slot="header" style="text-align: center">
        <span>下单成功</span>
      </p>
      <div class="success_styl">
        <Icon type="ios-checkmark-circle-outline" size="60" color="#3BB46D" />
        <div>
          <div>下单成功</div>
          <div>请仔细查看订单信息</div>
        </div>
      </div>
      <div class="user_content">
        <Form
          ref="form"
          :model="successForm"
          label-position="left"
          :label-width="80"
          style="width: 100%"
        >
          <Row>
            <Col span="24">
              <FormItem label="订单名称">
                <div class="form_content">{{ successForm.name }}</div>
              </FormItem>
            </Col>
            <Col span="12">
              <FormItem label="订单编码">
                <div class="form_content">{{ successForm.code }}</div>
              </FormItem>
            </Col>
            <Col span="12">
              <FormItem label="规格名称">
                <div class="form_content">
                  {{ successForm.productAttrName }}
                </div>
              </FormItem>
            </Col>
            <Col span="12">
              <FormItem label="订单总量">
                <div class="form_content">{{ successForm.nnum }}吨</div>
              </FormItem>
            </Col>
            <Col span="12">
              <FormItem label="订单总价">
                <div class="form_content">{{ successForm.nmoney }}元</div>
              </FormItem>
            </Col>
          </Row>
        </Form>
      </div>
      <div slot="footer">
        <Button
          type="text"
          @click="(modalShow = false), (modalShowSuccess = false)"
          >暂不派车</Button
        >
        <Button :loading="btnLoading" type="primary" @click="toPage"
          >立即派车</Button
        >
      </div>
    </Modal>
  </div>
</template>

<script>
import { mapGetters, mapMutations } from "vuex";
export default {
  components: {},
  data() {
    return {
      successForm: {},
      modalShowSuccess: false,
      nowAmount: "",
      infoData: {},
      nnum: "",
      price: "",
      totalPrice: "",
      btnLoading: false,
      modalShow: false,
    };
  },
  computed: {
    ...mapGetters(["store_userInfo", "store_goodsInfo"]),
  },
  mounted() {},
  methods: {
    toPage() {
      this.$router.push("/personalCenter/orderList");
    },
    openFun(val) {
      this.infoData = {
        ...val,
      };
      this.modalShow = true;
    },
    // 获取可用余额
    getUserMoneyFun() {
      let data = {
        companyCode: this.store_userInfo.code,
        customerId: this.store_userInfo.id,
      };
      this.httpPost(this.API.API_moneyHead, data)
        .then((res) => {
          if (res.data.length > 0) {
            this.nowAmount = res.data[0].nowAmount;
          }
        })
        .catch((err) => {
          console.error(err);
        });
    },
    // 提交修改信息
    submitFun() {
      this.httpPost(this.API.API_addOrderapi, this.infoData)
        .then((res) => {
          this.successForm = {
            ...res.data,
          };
          this.modalShowSuccess = true;
        })
        .catch((err) => {
          console.error(err);
        });
      // this.modalShow = false;
      //   this.$refs["formEle"].validate((valid) => {
      //     if (valid) {
      //       this.btnLoading = true;
      //       this.httpPost(
      //         this.API.API_takeOrderEdit,
      //         this.addFather
      //       )
      //         .then((res) => {
      //           this.$Message.success("编辑成功!");
      //           this.btnLoading = false;
      //           this.modalShow = false;
      //           this.$emit("apiSuccess");
      //         })
      //         .catch((err) => {
      //           this.btnLoading = false;
      //           console.error(err);
      //         });
      //     } else {
      //       this.$Message.error("请输入必填信息!");
      //     }
      //   });
    },
    toPageFun(item, index) {
      this.$router.push(item.path);
    },
  },
};
</script>
<style lang="less" scoped>
@import "~@/assets/styles/main.less";
@deep: ~">>>";

.user_content {
  background: #f6f7f9;
  .flex-x();
  padding: 14px 26px 14px 26px;
  font-size: 12px;

  .form_content {
    text-align: left;
  }
}
.success_styl {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.title_styl {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.infos_styl {
  width: 100%;
  background: #fef3e9;
  box-sizing: border-box;
  border: 1px solid #fce3ca;
  padding: 20px;
  display: flex;
  align-items: center;
  .smallInfo_styl {
    width: 33%;
    .text_styl {
      font-size: 20px;
      font-weight: bold;
      line-height: normal;
      color: #333333;
      margin-bottom: 5px;
      text-align: center;
    }
    .textRed_styl {
      font-size: 20px;
      font-weight: bold;
      line-height: normal;
      color: red;
      margin-bottom: 5px;
      text-align: center;
    }
  }
}
::v-deep .ivu-modal-header {
  background-image: url("~@/assets/images/modal_back500.png") !important;
}
/deep/.reButton_styl {
  background: transparent;
  border: none;
}
.billOrder_styl {
  width: 100%;
}
.modal_styl {
  position: relative;
  padding-bottom: 50px;
}
//   .title_styl {
//     color: #000000;
//     border-left: 3px solid @themeColor;
//     position: relative;
//     padding-left: 10px;

//     &::after {
//       content: "";
//       width: 2px;
//       height: 12px;
//       position: absolute;
//       left: 0;
//       top: 4px;
//     }
//   }
.formInfo {
  margin: 10px 0 30px 0;

  .ivu-form-item {
    margin-bottom: 0;
    border-top: #e8eaec 1px solid;
    @{deep} label {
      padding-left: 5px;
      border-right: 1px #e8eaec solid;
      background-color: #f8f8f9;
    }
    @{deep} .ivu-form-item-content {
      padding-left: 8px;
      padding-right: 8px;
      white-space: nowrap;
    }
  }

  @{deep} .overHeight label {
    height: 65px;
  }
  @{deep} .overHeight .ivu-form-item-content {
    height: 65px;
  }
  @{deep} .overHeightMap label {
    height: 150px;
  }
  @{deep} .overHeightMap .ivu-form-item-content {
    height: 150px;
  }
}
.blueColor {
  color: #52a0f3;
}
.blueLine {
  border: 3px #52a0f3 solid;
}
.grayLine {
  border: 3px #f2f2f2 solid;
}
.borderLeft {
  border-left: #e8eaec 1px solid;
}
.borderRight {
  border-right: #e8eaec 1px solid;
}
.borderBottom {
  border-bottom: #e8eaec 1px solid;
}
.borderTop {
  border-top: #e8eaec 1px solid;
}
.content-styl {
  width: 100%;

  .ivu-tabs-bar {
    margin-bottom: 0; //去掉tabs的margin
  }
}

.ivu-modal-content {
  border-radius: 12px;
}
/deep/.ivu-modal-body {
  padding: 20px 40px;
}
</style>
